package com.lyx.blogspace.admin.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.service.Contact;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc;

/**
 * @Author by lyx
 */
@Configuration
@EnableSwagger2WebMvc
@Profile("dev")
public class Knife4jAdminConfig {
    @Bean("adminAPI")
    public Docket createApiDoc() {
        Docket docket = new Docket(DocumentationType.SWAGGER_2)
            .apiInfo(buildApiInfo())
            // 分组名称
            .groupName("Admin 后台接口")
            .select()
            // 这里指定 Controller 扫描包路径
            .apis(RequestHandlerSelectors.basePackage("com.lyx.blogspace.admin.controller"))
            .paths(PathSelectors.any())
            .build();
        return docket;
    }

    /**
     * 构建 API 信息
     *
     * @return
     */
    private ApiInfo buildApiInfo() {
        return new ApiInfoBuilder()
            .title("BlogSpace 博客 Admin 后台接口文档") // 标题
            .description("BlogSpace 是一款简易博客。") // 描述
            .termsOfServiceUrl("https://www.qq.com/") // API 服务条款
            .contact(new Contact("lyxianowo", "https://www.qq.com", "1419101807@qq.com")) // 联系人
            .version("1.0") // 版本号
            .build();
    }
}
